package com.google.code.springbreeze.web.actions;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.google.code.springbreeze.entity.Account;
import com.google.code.springbreeze.entity.Page;
import com.google.code.springbreeze.service.AccountService;
import com.opensymphony.xwork2.ActionSupport;

@Controller
public class AccountAction extends ActionSupport{

	private static final long serialVersionUID = 7285689660566381918L;

	private transient static Log log = LogFactory.getLog(AccountAction.class);
	
	@Autowired
	private transient AccountService accountService;

	private Account account;
	
	private Page page = new Page();

	private String userid;
	
	private List<Account> accountList;

	public String getUserid() {
		return userid;
	}

	public void setUserid(String userid) {
		this.userid = userid;
	}

	
	public Page getPage() {
		return page;
	}

	public void setPage(Page page) {
		this.page = page;
	}

	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

  public List<Account> getAccountList() {
		return accountList;
	}

  public String getAllAccount() {
	  
	  page.setCount(28);
	  accountList = accountService.getAllAccount(page);
	  //log.debug(page.toString());
	  return SUCCESS;
  }
  
  public String saveAccount() {
	  accountService.insertAccount(account);
	  return SUCCESS;
  }
  
  public String updateAccount() {
	  accountService.updateAccount(account);
	  return SUCCESS;
  }
  
  public String insertAccount() {
	  accountService.insertAccount(account);
	  return SUCCESS;
  }
  
  public String deleteAccount() {
	  accountService.deleteAccountByUserID(userid);
	  return SUCCESS;
  }
  
  public String copyAccount() {
	  account =  accountService.getAccountByUserID(userid);
	  account.setUserid(null);
	  return SUCCESS;
  }
  
  public String getAccountByUserID() {
	  account = accountService.getAccountByUserID(userid);
	  return SUCCESS;
  }

}
